package woda.ink.controller.palteform;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import woda.ink.entity.fileEntity;
import woda.ink.entity.loginEntity;
import woda.ink.mapper.Commom;

@Controller
@RequestMapping("/plateForm")
public class brokerControllerImpl implements borkerController{

    @Autowired
    Commom commom;

    @Override
    @RequestMapping("/login")
    public String login(Model model) {
        return "Login";
    }
    @Override
    @RequestMapping("/homepage")
    public String Door(Model model) {
        return "homepage";
    }

    @Override
    @RequestMapping("/Article")
    public String Article(Model model) {
        return "Article";
    }

    @Override
    @RequestMapping("/Video")
    public String Video(Model model) {
        return "Video";
    }
    @Override
    @RequestMapping("/Courseware")
    public String Courseware(Model model) {
        return "Courseware";
    }
    @Override
    @RequestMapping("/System")
    public String System(Model model) {
        return "System";
    }

    @Override
    @RequestMapping("/Staff_ResourseList")
    public String Staff_ResourseList(Model model) {
        return "ResourseList";
    }

    @Override
    @RequestMapping("/StaffManage")
    public String Staff_Manage(Model model) {
        return "Smanage";
    }

    @Override
    @RequestMapping("/Staff_addResourse")
    public String Staff_addResourse(Model model) {
        return "addResourse";
    }


    @Override
    @RequestMapping("/Staff_EmployeeList")
    public String Staff_EmployeeList(Model model) {
        return "Employee";
    }


    @Override
    @RequestMapping("/Staff_EmployeeDetail")
    public String Staff_EmployeeDetail(@Param("employeeID")String employeeID,Model model) {
        loginEntity t = commom.EditEmployeeMapper("select * from plateform_Employee where employeeID = "+employeeID);
        model.addAttribute("t",t);
        return "EmployeeDetail";
    }

    @Override
    @RequestMapping("/ArticleDetail")
    public String ArticleDetail(@Param("sourseID")String sourseID, Model model) {
        fileEntity fileEntity = commom.EditSourceMapper("select * from plateform_file where sourseID = "+sourseID);
        model.addAttribute("sourseID",sourseID);
        model.addAttribute("link",fileEntity.getLink());
        return "ArticleDetail";
    }

    @Override
    @RequestMapping("/view")
    public String test(@Param("fileName")String fileName, Model model) {
        System.out.println("fileName::"+fileName);
        model.addAttribute("fileName",fileName);
        return "View";
    }

    @Override
    @RequestMapping("/Staff_ResourceDetail")
    public String Staff_ResourceDetail(@Param("sourseID")String sourseID, Model model) {
        fileEntity t = commom.EditSourceMapper("select * from plateform_file where sourseID = "+sourseID);
        String name = commom.count("select name from plateform_typeConf where type = '"+t.getType()+"'");
        System.out.println(name);
        if (name.length()>4){
            model.addAttribute("module",name.substring(5,name.length()));

        }else {
            model.addAttribute("module","无二级目录");
        }
        model.addAttribute("types",name.substring(0,4));
        model.addAttribute("t",t);
        return "ResourceDetail";
    }

    @Override
    @RequestMapping("/Staff_addEmployee")
    public String Staff_addEmployee(Model model) {
        return "addEmployee";
    }

    @Override
    @RequestMapping("/Staff_EmployeeLog")
    public String Staff_EmployeeLog(Model model) {
        return "EmployeeLog";
    }


    @Override
    @RequestMapping("/VideoDetil")
    public String VideoDetil(@Param("sourseID")String sourseID,Model model) {
        fileEntity tc = commom.EditSourceMapper("select * from plateform_file where sourseID = "+sourseID);
        String staticfile = "/file/"+tc.getFileName();
        model.addAttribute("url",tc.getUrl());
        model.addAttribute("title",tc.getTitle());
        model.addAttribute("fileExplain",tc.getFileExplain());
        model.addAttribute("sourseID",tc.getSourseID());
        model.addAttribute("fileName",tc.getFileName());
        model.addAttribute("staticfile",staticfile);

        return "videoDetil";
    }
}
